PREFIX=/usr/local
DESTDIR=
VERSION=$(shell cat VERSION)
GOFLAGS=-ldflags "-w -s -X main.appVersion=${VERSION} -extldflags=-static" -buildvcs=false
BINDIR=${PREFIX}/bin
BLDDIR = build
EXT=
CURRDIR=$(shell pwd)

# 如果没有指定GOARCH，则指定默认平台
ifeq ($(GOARCH),) 
GOARCH=amd64
endif

# 如果没有指定GOOS，则指定默认系统
ifeq ($(GOOS),) 
GOOS=linux
endif

# 如果是windows平台，则增加.exe扩展名
ifeq (${GOOS},windows)
    EXT=.exe
endif

# 定义应用
APPS = mss
all: $(APPS)

# 定义应用的编译目录
$(BLDDIR)/mss:        $(wildcard cmd/mss/*.go)

# 编译应用
$(BLDDIR)/%:
	@mkdir -p $(dir $@)
	go build ${GOFLAGS} -o $@${EXT} ./cmd/$* 

$(APPS): %: $(BLDDIR)/%

clean:
	rm -fr $(BLDDIR)/mss${EXT}

.PHONY: install clean all
.PHONY: $(APPS)
